<?php
require_once 'IEngine.php';

class LastFmEngine implements IEngine {
	private $name = "Last.fm";
	private $apiKey = "b25b959554ed76058ac220b7b2e0a026";
	//Your API Key is d2afbcc8fa458c5ade86eaaf8bf151af and your secret is 8eb80d21926e12c67e4673b6904d1f0d
	public function getTags() {
		return array("Music");
	}

	public function getName() {
		return $this->name;
	}

	public function search($term) {
		$results = array();
		$url = "http://ws.audioscrobbler.com/2.0/?method=artist.search&api_key=" . $this->apiKey . "&artist=" . urlencode($term);
		$str = file_get_contents($url);
		$page = str_get_html($str);
		$res = $page->find("artist");
		$res = $res;
		foreach ($res as $child) {
			$result = array();
			$name = $child->find("name");
			$href = $child->find("url");
			$image = $child->find("image");
			if (count($name) == 0) continue;
			//print_r($name[0]);
			$result['title'] = $name[0]->innertext();
			$result['href'] = "http://".$href[0]->innertext();
			$result['description'] = '<img src="'.$image[1]->innertext().'" />';
			$results[] = $result;
		}
		return $results;
	}

	public function engineLogo() {
		return '<img class="enginelogo" src="http://adamfehnel.com/images/layout/lastFM.png" />';
	}
}
?>